package com.cskaoyan.controller;

import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.bean.bo.OrderRefundBo;
import com.cskaoyan.module.bean.bo.OrderShipBo;
import com.cskaoyan.module.bean.param.BaseParam;
import com.cskaoyan.module.bean.vo.OrderChannelVo;
import com.cskaoyan.module.bean.vo.OrderDetailVo;

import com.cskaoyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    //http://182.92.235.201:8083/admin/order/list?page=1&limit=20&sort=add_time&order=desc&start=&end=
    @RequestMapping("list")
    public BaseRespVo orderList(BaseParam baseParam, Integer userId, String orderStatusArray,
                                String start,String end,String orderSn){
        return BaseRespVo.ok(orderService.selectOrderList(baseParam,userId,orderStatusArray,start,end,orderSn));
    }


    @RequestMapping("channel")
    public BaseRespVo orderChannel(){
        return BaseRespVo.ok(orderService.selectOrderChannel());
    }


    @RequestMapping("detail")
    public BaseRespVo orderDetail(Integer id){
        return BaseRespVo.ok(orderService.selectOrderOrUserOrGoodsList(id),"成功");
    }


    @PostMapping("delete")
    public BaseRespVo orderDelete(@RequestBody String orderId){
        int code = orderService.updateOrderDeleted(orderId);
        if (code ==1){
            return BaseRespVo.ok("成功");
        }else {
            return BaseRespVo.invalidData();
        }
    }


    //182.92.235.201:8083/admin/order/refund
    @PostMapping("refund")
    public BaseRespVo orderRefund(@RequestBody OrderRefundBo orderRefundBo){
        int code = orderService.orderRefund(orderRefundBo);
        return BaseRespVo.ok("成功");
    }


    //http://localhost:8083/admin/order/ship
    @PostMapping("ship")
    public BaseRespVo ship(@RequestBody OrderShipBo orderShipBo){
        int code = orderService.orderShip(orderShipBo);
        return BaseRespVo.ok(null);
    }
    @PostMapping("reply")
    public BaseRespVo reply(@RequestBody Map map){
        BaseRespVo vo = orderService.replyCommentById(map);
        return vo;
    }
}
